package cn.cvs.servlet;


import cn.cvs.dao.ResumeDao;
import cn.cvs.pojo.Resume;
import cn.cvs.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/Inserservlet")
public class Inserservlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        Resume resume = new Resume();
        resume.setUserName(req.getParameter("userName"));
        resume.setSex(req.getParameter("sex"));
        resume.setAddress(req.getParameter("address"));
        resume.setBirth(req.getParameter("birth"));
        resume.setTelephone(req.getParameter("telephone"));
        resume.setSchool(req.getParameter("school"));
        System.out.println(req.getParameter("status"));
        resume.setStatus(Integer.parseInt(req.getParameter("status")));
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        int insert = sqlSession.getMapper(ResumeDao.class).insert(resume);
        if(insert>0){
            req.getRequestDispatcher("index.jsp").forward(req,resp);
        }else{
            req.getRequestDispatcher("add.jsp").forward(req,resp);
        }
        MyBatisUtil.closeSqlSession(sqlSession);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
